package com.network.controller;

import com.google.gson.Gson;
import com.network.entity.Equipment;
import com.network.entity.FileSave;
import com.network.entity.User;
import com.network.qo.FileQo;
import com.network.qo.PageQo;
import com.network.service.EquipmentService;
import com.network.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
public class EquipController
{

    @Autowired
    EquipmentService equipmentService;

    PageResult pageResult=null;

    @RequestMapping(value ="/get/getEquipByPage",method = RequestMethod.GET)
    public CompletableFuture<String> getEquipByPage(PageQo pageQo)
    {
       return CompletableFuture.supplyAsync(()->{

           Page<Equipment> equipmentPage=equipmentService.getEquipByPage(pageQo);

           pageResult=new PageResult();
           pageResult.setCode(0);
           pageResult.setData(equipmentPage.getContent());
           return new Gson().toJson(pageResult);
        });
    }

    @RequestMapping(value ="/get/getFileByEquipPage",method = RequestMethod.GET)
    public CompletableFuture<String> getFileByEquipPage(FileQo fileQo)
    {
        return CompletableFuture.supplyAsync(()->{

            pageResult=equipmentService.getFileByEquipIp(fileQo);
            return new Gson().toJson(pageResult);
        });
    }
}
